package edu.uwm.capstone.diasmart.database;

import edu.uwm.capstone.diasmart.types.EntryContext;
import edu.uwm.capstone.diasmart.types.EntryTypeFactory;
import edu.uwm.capstone.util.Identifiable;
import edu.uwm.capstone.util.StringUtil;

public class Entry implements Identifiable {
	private long categoryId = -1L;
	private long entryDate;
	private long id = -1L;
	private boolean modified = false;
	private String note;
	private long subTypeId = -1L;
	private int type;
	private double value;

	public Entry() {
	}

	public Entry(long id) {
		this.id = id;
	}

	public Entry(long id, long entryDate, int type, long categoryId,
			long subTypeId, String note, double value) {
		this.id = id;
		this.entryDate = entryDate;
		this.type = type;
		this.categoryId = categoryId;
		this.subTypeId = subTypeId;
		this.note = note;
		this.value = value;

	}

	public long getCategoryId() {
		return this.categoryId;
	}

	public long getEntryDate() {
		return this.entryDate;
	}

	@Override
	public long getId() {
		return this.id;
	}

	public String getNote() {
		return this.note;
	}

	public long getSubTypeId() {
		return this.subTypeId;
	}

	public int getType() {
		return this.type;
	}

	public double getValue() {
		return this.value;
	}

	public boolean isModified() {
		return this.modified;
	}

	public void setCategoryId(long paramLong) {
		if (this.categoryId != paramLong) {
			this.categoryId = paramLong;
			this.modified = true;
		}
	}

	public void setEntryDate(long paramLong) {
		if (this.entryDate != paramLong) {
			this.entryDate = paramLong;
			this.modified = true;
		}
	}

	void setId(long paramLong) {
		this.id = paramLong;
	}

	void setModified(boolean paramBoolean) {
		this.modified = paramBoolean;
	}

	public void setNote(String paramString) {
		if (!StringUtil.isEqual(this.note, paramString)) {
			this.note = paramString;
			this.modified = true;
		}
	}

	public void setSubTypeId(long paramLong) {
		if (this.subTypeId != paramLong) {
			this.subTypeId = paramLong;
			this.modified = true;
		}
	}

	public void setType(int paramInt) {
		if (this.type != paramInt) {
			this.type = paramInt;
			this.modified = true;
		}
	}

	public void setValue(double paramDouble) {
		if (this.value != paramDouble) {
			this.value = paramDouble;
			this.modified = true;
		}
	}
	
	 public void setValue(EntryContext paramEntryContext, String paramString)
	  {
	    setValue(EntryTypeFactory.getInstance(this.type).toValue(paramEntryContext, paramString));
	  }

	public String toString() {
		return "Type: " + this.type + ", Value:" + this.value;
	}

}
